package cn.bluethink.eguan.okrtask.service;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.stream.Collectors;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.StringUtils;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;

import cn.bluethink.eguan.core.service.EgActionService;
import cn.bluethink.eguan.core.service.EgUserService;
import cn.bluethink.eguan.filter.NameFilter;
import cn.bluethink.eguan.model.core.EgActionType;
import cn.bluethink.eguan.model.core.EgConfigInfo;
import cn.bluethink.eguan.model.core.EgOType;
import cn.bluethink.eguan.model.core.EgObject;
import cn.bluethink.eguan.model.core.EgOtAction;
import cn.bluethink.eguan.model.core.EgTask;
import cn.bluethink.eguan.model.core.EgTaskStatus;
import cn.bluethink.eguan.model.core.EgUser;
import cn.bluethink.eguan.model.okrtask.EgOkrTask;
import cn.bluethink.eguan.model.okrtask.EgTaskKR;
import cn.bluethink.eguan.okrtask.entity.EgTaskKREntity;
import cn.bluethink.eguan.okrtask.entity.TaskKREntity;
import cn.bluethink.eguan.okrtask.mapper.EgTaskKRMapper;
import cn.bluethink.eguan.result.PageInfo;
import cn.bluethink.eguan.utils.DateUtil;
import cn.bluethink.eguan.utils.IdMakerUtils;
import tk.mybatis.mapper.entity.Example;

@Service
public class EgTaskKRService {

    private IdMakerUtils idUtil = new IdMakerUtils();

    @Autowired
    private EgTaskKRMapper taskkrMapper;

    @Autowired
    private EgUserService userService;

    @Autowired
    private EgActionService actionService;

    @Autowired
    private EgConfigInfo configInfo;

    /**
     * 新增工作任务关键项
     * 
     * @param taskkr
     * @return
     * @throws Exception
     */
    @Transactional(transactionManager = "eguanTransactionManager", rollbackFor = Exception.class)
    public EgTaskKR create(EgTask task, String content, Long uid) throws Exception {
        // 1、Id生成器生成主键Id
        Long uuid = idUtil.nextId();
        // 2、转换为实体
        EgTaskKREntity entity = new EgTaskKREntity();
        entity.setKrid(uuid);
        entity.setTid(task.getId());
        entity.setContent(content);
        entity.setStatus(EgTaskStatus.STATUS_NEW);
        // 获取计划中工作任务总个数，并设置默认顺序
        int sort = taskkrMapper.taskkrCount(task.getId());
        entity.setSort(sort + 1);
        // 3、新增关键项
        if (taskkrMapper.insert(entity) == 0)
            return null;
        EgTaskKR result = entity.createKeyResult();
        // 创建动作
        int atid = EgActionType.CREATE;
        if (!saveAction(task, result, null, atid, uid, "")) {
            throw new RuntimeException("新增动作失败！");
        }
        return result;
    }

    /**
     * 修改任务关键项（基本信息）
     * 
     * @param taskkr
     * @return
     * @throws Exception
     */
    @Transactional(transactionManager = "eguanTransactionManager", rollbackFor = Exception.class)
    public EgTaskKR update(EgOkrTask task, EgTaskKR oldkr, EgTaskKR taskkr, Long uid) throws Exception {
        String field = "basic";

        taskkr.setStatus(oldkr.getStatus());
        taskkr.setScore(oldkr.getScore());
        taskkr.setEvaluate(oldkr.getEvaluate());
        taskkr.setFtime(oldkr.getFtime());
        if (taskkr.getRemark() == null || taskkr.getRemark().equals(""))
            taskkr.setRemark(oldkr.getRemark());
        // 更新截止日期/指派人时，获取更新字段标识并设置对应状态
        field = updateActionAndField(oldkr, taskkr, field);
        EgUser olduser = oldkr.getDouser();
        // 2、转换为实体
        if (taskkr.getEtime() != null)
            taskkr.setEtime(DateUtil.dateTime(taskkr.getEtime(), 18, 00, 00));
        EgTaskKREntity entity = new EgTaskKREntity(taskkr, false);
        // 3、更新关键项
        if (taskkrMapper.updateTaskkr(entity) == 0)
            return null;
        // 如果有动作记录，则记录原内容
        taskkr.setKrContent(oldkr.getKrContent());
        if (!saveAction(task, taskkr, olduser, EgActionType.UPDATE, uid, field)) {
            throw new RuntimeException("新增动作失败！");
        }
        return entity.createKeyResult();
    }

    /**
     * 修改任务关键项（状态）
     * 
     * @param taskkr
     * @return
     * @throws Exception
     */
    @Transactional(transactionManager = "eguanTransactionManager", rollbackFor = Exception.class)
    public EgTaskKR updateStatus(EgOkrTask task, EgTaskKR taskkr, EgTaskKR updatekr, Long uid) throws Exception {
        String field = "";
        Integer atid = null;
        Long tid = updatekr.getId();
        Integer status = updatekr.getStatus();
        Date etime = taskkr.getEtime();
        if (etime != null && DateUtil.dateCompare(etime, new Date()) < 0) {
            status = status | EgTaskStatus.STATUS_DELAY;
        }
        // 1、判断状态是否为空，为空不更新
        if (tid == null || status == null)
            return null;
        // 2、判断状态是否更新
        if (updatekr.getStatus() == taskkr.getStatus())
            return null;
        // 3、构建关键项实体
        EgTaskKREntity entity = new EgTaskKREntity(taskkr, false);
        entity.setKrid(updatekr.getId());
        // 4、如果修改状态为未开始，设置关键项状态
        if (status == EgTaskStatus.STATUS_NEW || status == EgTaskStatus.STATUS_DELAY) {
            entity.setStatus(status);
            entity.setFtime(null);
            // 如果该关键项的原状态是完成或延误完成,记录取消完成的操作
            if ((taskkr.getStatus() & EgTaskStatus.STATUS_FINISH) == EgTaskStatus.STATUS_FINISH) {
                field = "delayFinish";
                atid = EgActionType.FINISH;
            }
        }
        // 5、如果修改状态为已完成，设置关键项状态和完成时间
        else if ((status & EgTaskStatus.STATUS_FINISH) == EgTaskStatus.STATUS_FINISH) {
            field = "finish";
            atid = EgActionType.FINISH;
            entity.setStatus(status);
            entity.setFtime(new Date());
        }
        // 6、更新关键项状态
        if (taskkrMapper.updateTaskkr(entity) == 0)
            return null;
        if (atid != null && !saveAction(task, taskkr, null, atid, uid, field)) {
            throw new RuntimeException("新增动作失败！");
        }
        return entity.createKeyResult();
    }

    /**
     * 对关键项评价打分（score不能为空）/ 备注
     * 
     * @param taskkr
     * @return
     * @throws Exception
     */
    @Transactional(transactionManager = "eguanTransactionManager", rollbackFor = Exception.class)
    public EgTaskKR evaluateScore(EgOkrTask task, EgTaskKR krdetail, EgTaskKR taskkr, Long uid) throws Exception {
        // 1、转换为实体
        EgTaskKREntity entity = new EgTaskKREntity(taskkr, false);
        // 2、更新关键项
        if (taskkrMapper.updateTaskkr(entity) == 0)
            return null;
        int atid = 0;

        String field = "";
        String oldEvaluate = krdetail.getEvaluate();
        String evaluate = taskkr.getEvaluate();
        Integer oldScore = krdetail.getScore();
        Integer score = taskkr.getScore();

        if (!objEquals(oldEvaluate, evaluate))
            field = "evaluate";
        if (score != null && !objEquals(oldScore, score)) {
            if (field.equals("evaluate"))
                field = "both";
            else
                field = "score";
        }

        // 没有更新
        if (field.equals(""))
            return taskkr;

        taskkr.setKrContent(krdetail.getKrContent());
        // 如果尚未评分
        if (krdetail.getScore() == null) {
            atid = EgActionType.EVALUATE; // 首次评价动作
        } else {
            atid = EgActionType.UPDATE; // 更新动作 更新评价
        }

        if (!saveAction(task, taskkr, null, atid, uid, field)) {
            throw new RuntimeException("新增动作失败！");
        }
        return entity.createKeyResult();
    }

    /**
     * 更新备注
     * 
     * @param taskkr
     * @param uid
     * @return
     * @throws Exception
     */
    @Transactional(transactionManager = "eguanTransactionManager", rollbackFor = Exception.class)
    public EgTaskKR updateRemark(EgOkrTask task, EgTaskKR taskkr, Long uid) throws Exception {
        // 1、转换为实体
        EgTaskKREntity entity = new EgTaskKREntity(taskkr, false);
        // 2、更新关键项
        if (taskkrMapper.updateTaskkr(entity) == 0)
            return null;
        int atid = EgActionType.UPDATE; // 更新动作 更新备注
        if (!saveAction(task, taskkr, null, atid, uid, "remark")) {
            throw new RuntimeException("新增动作失败！");
        }
        return entity.createKeyResult();
    }

    /**
     * 根据主键Id删除关键项
     * 
     * @param krid
     * @return
     * @throws Exception
     */
    @Transactional(transactionManager = "eguanTransactionManager", rollbackFor = Exception.class)
    public Long del(EgTask task, Long uid, EgTaskKR taskkr) throws Exception {
        EgTaskKREntity entity = taskkrMapper.selectByPrimaryKey(taskkr.getId());
        int tasksort = entity.getSort();
        int taskcount = taskkrMapper.taskkrCount(task.getId());
        int result = 0;
        // 如果当前被删除的关键项不是最后一个，则需要对收到影响的对象进行排序修订
        if (tasksort < taskcount) {
            result = taskkrMapper.updateSort(tasksort, taskcount, entity.getTid(), false);
        }
        // 否则：不需要做调整
        else {
            result = 1;
        }
        if (result > 0) {
            if (taskkrMapper.deleteByPrimaryKey(taskkr.getId()) == 0)
                return null;
        }
        // 删除动作
        int atid = EgActionType.DELETE;
        if (!saveAction(task, taskkr, null, atid, uid, "")) {
            throw new RuntimeException("新增动作失败！");
        }
        return taskkr.getId();
    }

    /**
     * 根据工作任务ID删除对应的关键项
     * 
     * @param tid
     * @return
     * @throws Exception
     */
    @Transactional(transactionManager = "eguanTransactionManager", rollbackFor = Exception.class)
    public Long deleteByTid(Long tid) throws Exception {
        // 1、查询该工作任务Id下是否有关键项
        NameFilter filter = new NameFilter();
        filter.setId(tid);
        List<EgTaskKR> keyresult = query(filter).getList();
        // 2、没有，直接返回任务ID
        if (keyresult == null || keyresult.size() == 0)
            return tid;
        // 3、有，删除该任务下的关键项
        Example example = new Example(EgTaskKREntity.class);
        example.and().andEqualTo("tid", tid);
        if (taskkrMapper.deleteByExample(example) == 0)
            return null;
        return tid;
    }

    /**
     * 根据关键项主键Id查询关键项信息
     * 
     * @param krid
     * @return
     * @throws Exception
     */
    public EgTaskKR detail(Long krid) throws Exception {
        EgTaskKREntity entity = taskkrMapper.selectByPrimaryKey(krid);
        if (entity == null)
            return null;
        EgTaskKR taskkr = entity.createKeyResult();
        return taskkr;
    }

    /**
     * 根据任务Id查询关键项列表
     * 
     * @param tid
     * @return
     * @throws Exception
     */
    public PageInfo<EgTaskKR> query(NameFilter filter) throws Exception {
        Integer pageNum = filter.getPageNum() == null ? 1 : filter.getPageNum();
        Integer pageSize = filter.getPageSize() == null ? 20 : filter.getPageSize();
        // 1、获取当前任务Id
        Long tid = filter.getId();
        // 2、构造查询条件
        Example example = new Example(EgTaskKREntity.class);
        example.and().andEqualTo("tid", tid);
        example.orderBy("sort");
        // 3、根据任务Id查询关键项实体列表
        PageHelper.startPage(pageNum, pageSize);
        Page<TaskKREntity> entities = (Page<TaskKREntity>) taskkrMapper.selectTaskkrList(tid);
        // 4、实体列表不为空，将实体列表转换为模型列表并返回
        if (entities != null && entities.size() > 0) {
            List<EgTaskKR> result = new ArrayList<>();
            result = entities.stream().map(e -> e.createKeyResult()).collect(Collectors.toList());
            return new PageInfo<>(result, entities);
        }
        return new PageInfo<>(new ArrayList<>());
    }

    /**
     * 拖拽排序
     * 
     * @param krid
     * @param sort
     * @return
     * @throws Exception
     */
    public Long sort(Long krid, int sort) throws Exception {
        EgTaskKREntity entity = taskkrMapper.selectByPrimaryKey(krid);
        int tasksort = entity.getSort();
        if (sort == tasksort)
            return krid;
        int result = 0;
        // 更新受影响的任务关键结果排序
        if (sort > tasksort) {
            result = taskkrMapper.updateSort(tasksort, sort, entity.getTid(), false);
        } else {
            result = taskkrMapper.updateSort(sort, tasksort, entity.getTid(), true);
        }
        // 更新被拖拽的关键结果排序
        if (result > 0) {
            if (taskkrMapper.updateSortByTid(krid, sort) > 0) {
                return krid;
            }
        }
        return null;
    }

    /**
     * 根据条件获取任务Id列表
     * 
     * @param douid
     * @param status
     * @param egidList
     * @return
     * @throws Exception
     */
    public List<Long> taskIdsByKR(Long douid, Integer status, List<Long> egidList) throws Exception {
        String whereSql = buildTaskSql(douid, status, egidList);
        List<Long> taskIds = taskkrMapper.taskIdsByKR(whereSql);
        if (taskIds != null && taskIds.size() > 0) {
            return taskIds;
        }
        return null;
    }

    /**
     * 定时更新当前工作任务状态为已延误/延误进行/延误完成/
     * 
     * @throws Exception
     */
    @Transactional
    @Scheduled(cron = "${task.date}")
    public void updateStatusToDelay() throws Exception {
        taskkrMapper.updateStatusToDelay();
    }

    private String buildTaskSql(Long douid, Integer status, List<Long> egidList) throws Exception {
        String whereSql = "";

        List<String> whereSqlList = new ArrayList<>();

        // 任务删除状态为0（未删除）
        whereSqlList.add("et.del_flag = 0");

        if (egidList != null && egidList.size() > 0) {
            whereSqlList.add(" et.pos_oid in (" + StringUtils.collectionToDelimitedString(egidList, ",") + ")");
        } else {
            return null;
        }

        // 1、查询工作任务列表
        whereSqlList.add(" et.otype = " + EgOType.OKR_TASK);
        // 2、判断被指派人Id是否大于0，根据被指派人Id查询 指派给该用户 工作任务列表
        if (douid > 0) {
            whereSqlList.add(" kr.douid = " + douid);
            // 3、如果状态为null，根据被指派人Id查询【计划中+进行中+已暂停】的工作任务列表， 即任务状态不是已完成的任务列表
            if (status == null) {
                whereSqlList.add(EgTaskStatus.STATUS_FINISH + " & kr.status <> " + EgTaskStatus.STATUS_FINISH);
            }
        }
        // 4、如果状态不为空，并且不为延误状态，根据状态查询【当前状态+当前状态（已延误）】的工作任务列表
        if (status != null) {
            // 如果状态为进行中，将进行中/延误处理和已暂停的任务全部查询出来
            if ((status & EgTaskStatus.STATUS_HANDLE) == EgTaskStatus.STATUS_HANDLE) {
                whereSqlList.add(" kr.status in (" + status + ", " + (status | EgTaskStatus.STATUS_DELAY) + ", "
                        + EgTaskStatus.STATUS_PAUSE + ")");
            }
            // 否则，如果不为延误状态，根据状态查询【当前状态+当前状态（已延误）】的工作任务列表
            else if (status != EgTaskStatus.STATUS_DELAY) {
                whereSqlList.add(" kr.status in (" + status + ", " + (status | EgTaskStatus.STATUS_DELAY) + ")");
            }
        }
        // 5、设置查询条件AND连接符
        if (whereSqlList.size() > 0) {
            whereSql += String.join(" AND ", whereSqlList);
        }
        return whereSql;
    }

    /**
     * 更新截止日期/指派人时，获取更新字段标识并设置对应状态
     * 
     * @param task
     * @param oldkr
     * @param taskkr
     * @param atid
     * @param field
     * @throws Exception
     */
    private String updateActionAndField(EgTaskKR oldkr, EgTaskKR taskkr, String field) throws Exception {

        // 1、如果截止日期为null，以任务截止日期为准
        Date oldetime = oldkr.getEtime();
        Date etime = taskkr.getEtime();
        // 2、如果修改截止日期，并且尚未完成,动作记录为修改截止日期
        if (oldetime == null && etime == null) {
            field = "basic";
        } else if (oldetime != null && etime != null && DateUtil.dateCompare(etime, oldetime) == 0) {
            field = "basic";
        } else {
            field = "etime";

            if (etime != null) {
                if (DateUtil.dateCompare(etime, new Date()) < 0 && (oldkr.getStatus() == EgTaskStatus.STATUS_NEW
                        || oldkr.getStatus() == EgTaskStatus.STATUS_FINISH)) {
                    taskkr.setStatus(oldkr.getStatus() | EgTaskStatus.STATUS_DELAY);
                } else if (DateUtil.dateCompare(etime, new Date()) >= 0
                        && (oldkr.getStatus() == EgTaskStatus.STATUS_DELAY
                                || oldkr.getStatus() == (EgTaskStatus.STATUS_FINISH | EgTaskStatus.STATUS_DELAY))) {
                    taskkr.setStatus(oldkr.getStatus() ^ EgTaskStatus.STATUS_DELAY);
                }
            }
        }
        // 3、获取被指派人ID
        EgUser olduser = oldkr.getDouser();
        EgUser douser = taskkr.getDouser();
        // 4、如果修改的是指派人，动作记录为修改指派人
        if (douser != null && douser.getId() != null && !olduser.equals(douser)) {
            if (field.equals("etime")) {
                field = "etime & douser";
            } else {
                field = "douser";
            }
        }
        return field;
    }

    /**
     * 验收项的动作：创建/删除/评分/评价 注意：被操作的对象类型和结果对象类型相同,除了删除的结果对象类型为工作任务
     * 
     * @param task
     * @param taskkr
     * @param oldDOuser
     * @param atid
     * @param uid
     * @param field
     * @return
     * @throws Exception
     */
    private Boolean saveAction(EgTask task, EgTaskKR taskkr, EgUser oldDOuser, Integer atid, Long uid, String field)
            throws Exception {
        // 操作者信息
        EgUser user = userService.getUser(uid, false);
        if (user == null) {
            return false;
        }
        // 操作对象类型/操作对象类型名称/操作对象的名称
        Integer otype = EgOType.CHECK_ITEM;
        String otypeName = configInfo.otypes().get(otype).getName();
        String oname = taskkr.getKrContent();
        // 动作操作对象
        EgObject obj = new EgObject(taskkr.getId(), oname, new EgOType(otype, null));
        // 动作名称
        String actionName = configInfo.actionTypes().get(atid).getName();
        EgOtAction otAction = configInfo.actionTypes(otype).get(atid);
        // 结果对象类型/结果对象(默认为当前用户)
        EgOType rtype = otAction != null ? otAction.getRtype():null;
        // 动作标识
        Integer actFlag = otAction != null ? otAction.getFlag():null;
        // 结果对象(除了创建、删除，其他的操作均为用户)
        EgObject result = new EgObject(uid, user.getName(), rtype);
        // 动作拼接语句
        String rcontent = user.getName() + " " + actionName + "了 " + otypeName + " 【" + oname+"】";
        // 动作发生的位置
        EgObject pos = null;
        if (task != null) {
            pos = new EgObject(task.getPos().getId(), null, new EgOType(task.getPos().getType().getOtid(), null));
        }
        // 动作标识(默认为操作记录+动态)
        //Integer actionFlag = EgActionFlag.OPREATE | EgActionFlag.DYNAMIC;
        // 仅作为评分时 的 拼接语句
        String rcontent1 = null;
        switch (atid) {
        // 如果是创建验收项，操作对象为工作任务，结果对象为验收项
        case EgActionType.CREATE:
            otype = EgOType.OKR_TASK;
            otAction = configInfo.actionTypes(otype).get(atid);
            rtype = otAction.getRtype();
            actFlag = otAction.getFlag();
            oname = task.getName();
            rcontent = user.getName() + " " + actionName + "了 " + configInfo.otypes().get(EgOType.CHECK_ITEM).getName()
                    + " 【" + taskkr.getKrContent()+"】";
            obj = new EgObject(task.getId(), oname, new EgOType(otype, null));
            result = new EgObject(taskkr.getId(), taskkr.getKrContent(), rtype);
            break;
        // 如果是重新评分，调整拼接语句
        case EgActionType.UPDATE:
            if (field.equals("both")) {
                rcontent1 = new String(rcontent) + " 的评分为 " + taskkr.getScore();
            } else if (field.equals("etime & douser")) {
                atid = EgActionType.DISPATCH;
                rcontent1 = new String(rcontent) + " 的截止时间为 " + DateUtil.formatDate(taskkr.getEtime(), "");
            } else if (field.equals("douser")) {
                atid = EgActionType.DISPATCH;
            }
            rcontent = getRcontent(taskkr, user, oldDOuser, rcontent, field);
            break;
        // 如果是删除验收项，操作对象为验收项，结果对象为工作任务
        case EgActionType.DELETE:
            oname = task.getName();
            result = new EgObject(taskkr.getTid(), oname, rtype);
            break;
        // 如果是取消完成验收项
        case EgActionType.FINISH:
            if (field.equals("delayFinish")) {
                rcontent = getRcontent(taskkr, user, oldDOuser, rcontent, field);
            }
            break;
        default:
            break;
        }
        if (rcontent != null && !actionService.create(atid, obj, result, rcontent, pos, uid, actFlag)) {
            return false;
        }
        // 如果评分拥有评分拼接语句，则添加两条动作记录
        if (rcontent1 != null && !rcontent1.equals("")) {
            atid = EgActionType.UPDATE;
            if (!actionService.create(atid, obj, result, rcontent1, pos, uid, actFlag)) {
                return false;
            }
        }
        return true;
    }

    /**
     * 获取 动作拼接内容
     * 
     * @param taskkr
     * @param user
     * @param oldDoUser
     * @param rcontent
     * @param field
     * @return
     * @throws Exception
     */
    private String getRcontent(EgTaskKR taskkr, EgUser user, EgUser oldDoUser, String rcontent, String field)
            throws Exception {
        switch (field) {
        case "score":
            rcontent += " 的评分为 " + taskkr.getScore();
            break;
        case "remark":
            rcontent += " 的备注 " + taskkr.getRemark();
            break;
        case "etime":
            if (taskkr.getEtime() == null) {
                rcontent = user.getName() + " 设置该关键项无截止日期";
            } else {
                rcontent += " 的截止时间为 " + DateUtil.formatDate(taskkr.getEtime(), "");
            }
            break;
        case "douser":
            oldDoUser = userService.getUser(oldDoUser.getId(), false);
            if (taskkr.getDouser() != null && taskkr.getDouser().getId() != null && taskkr.getDouser().getId() > 0) {
                EgUser douser = userService.getUser(taskkr.getDouser().getId(), false);
                rcontent = user.getName() + " 将 关键项 【" + taskkr.getKrContent() + "】 指派给了 " + douser.getName();
            } else if (oldDoUser != null && oldDoUser.getId() != null && oldDoUser.getId() > 0) {
                rcontent = user.getName() + " 取消了对 " + oldDoUser.getName() + "的关键项 【" + taskkr.getKrContent() + "】 指派";
            }
            break;
        case "etime & douser":
            oldDoUser = userService.getUser(oldDoUser.getId(), false);
            if (taskkr.getDouser() != null && taskkr.getDouser().getId() != null && taskkr.getDouser().getId() > 0) {
                EgUser douser = userService.getUser(taskkr.getDouser().getId(), false);
                rcontent = user.getName() + " 将 关键项 【" + taskkr.getKrContent() + "】 指派给了 " + douser.getName();
            } else if (oldDoUser != null && oldDoUser.getId() != null && oldDoUser.getId() > 0) {
                rcontent = user.getName() + " 取消了对 " + oldDoUser.getName() + "的关键项 【" + taskkr.getKrContent() + "】 指派";
            }
            break;
        case "both":
            rcontent += " 的评价 " + taskkr.getEvaluate();
            break;
        case "delayFinish":
            rcontent = user.getName() + " 取消完成了 验收项 " + taskkr.getKrContent();
            break;
        default:
            rcontent = null;
            break;
        }
        return rcontent;
    }

    /**
     * 比较两个对象是否相等
     * 
     * @param o1
     * @param o2
     * @return
     * @throws Exception
     */
    private boolean objEquals(Object o1, Object o2) throws Exception {
        if (o1 == null && o2 == null)
            return true;
        if (o1 != null && o2 != null) {
            if (o1 instanceof String && o2 instanceof String) {
                return o1.toString().trim().equals(o2.toString().trim());
            }
            return o1 == o2;
        }
        return false;
    }
}
